import { getBaseURL, get, post, deletes, getIntURL } from "./request";

const HttpManager = {
  // 获取图片信息
  attachImageUrl: (url) => {
    const result = url
      ? `${getIntURL()}${url}`
      : "https://marketplace.canva.cn/w5_ps/MAB60Vw5_ps/2/tl/canva-%E9%9F%B3%E4%B9%90%E7%AC%94%E8%AE%B0%E5%9B%BE%E6%A0%87%E9%9F%B3%E4%B9%90%E7%AC%94%E8%AE%B0%E5%9B%BE%E6%A0%87-music-note-icon-music-note-icon-MAB60Vw5_ps.png";
    // console.log(result);
    return result;
  },
  // =======================> 用户 API
  //修改密码
  getFirst: (params) => post(`common/code/request`, params),
  getSecond: (params) => post(`common/code/email`, params),
  getThird: (params) => post(`findPassword`, params),
  // 登录
  signIn: (params) => post(`login`, params),
  // 注册
  SignUp: (params) => post(`user/add`, params),
  // 删除用户
  deleteUser: (id) => get(`user/delete?id=${id}`),
  // 更新用户信息
  updateUserMsg: (params) => post(`user/update`, params),
  updateUserPassword: (params) => post(`user/updatePassword`, params),
  // 返回指定ID的用户
  getUserOfId: (id) => get(`user/detail?id=${id}`),
  // 更新用户头像
  uploadUrl: (userId) => `${getBaseURL()}/user/avatar/update?id=${userId}`,

  // 返回特定的用户
  getListUserOfUser: (keywords) => get(`user/searchUser?keywords=${keywords}`),

  // =======================> 歌单 API
  // 获取全部歌单
  getSongList: () => get("songList"),
  // 获取歌单类型
  getSongListOfStyle: (style) => get(`songList/style/detail?style=${style}`),
  // 返回标题包含文字的歌单
  getSongListOfLikeTitle: (keywords) =>
    get(`songList/likeTitle/detail?title=${keywords}`),
  // 返回歌单里指定歌单ID的歌曲
  getListSongOfSongId: (songListId) =>
    get(`listSong/detail?songListId=${songListId}`),
  //返回用户歌单
  getUserSongList: (userId) => get(`songList/usersonglist?userid=${userId}`),
  //增加歌曲到歌单
  addToSongList: (params) => post(`listSong/add`, params),

  // =======================> 歌手 API
  // 返回所有歌手
  getAllSinger: () => get("singer"),
  // 通过性别对歌手分类
  getSingerOfSex: (sex) => get(`singer/sex/detail?sex=${sex}`),

  // =======================> 收藏 API
  // 返回的指定用户ID的收藏列表
  getCollectionOfUser: (userId) => get(`collection/detail?userId=${userId}`),
  // 添加收藏的歌曲 type: 0 代表歌曲， 1 代表歌单
  setCollection: (params) => post(`collection/add`, params),

  //删除收藏
  deleteCollection: (userId, songId) =>
    deletes(`collection/delete?userId=${userId}&&songId=${songId}`),

  isCollection: (params) => post(`collection/status`, params),

  // =======================> 评分 API
  // 提交评分
  setRank: (params) => post(`rankList/add`, params),
  // 获取指定歌单的评分
  getRankOfSongListId: (songListId) => get(`rankList?songListId=${songListId}`),
  // 获取指定用户的歌单评分
  getUserRank: (consumerId, songListId) =>
    get(`/rankList/user?consumerId=${consumerId}&songListId=${songListId}`),

  // =======================> 评论 API
  // 添加评论
  setComment: (params) => post(`comment/add`, params),
  // 删除评论
  deleteComment: (id) => get(`comment/delete?id=${id}`),
  // 点赞
  setSupport: (params) => post(`comment/like`, params),
  // 返回所有评论
  getAllComment: (type, id) => {
    let url = "";
    if (type === 1) {
      url = `comment/songList/detail?songListId=${id}`;
    } else if (type === 0) {
      url = `comment/song/detail?songId=${id}`;
    }
    return get(url);
  },

  // =======================> 歌曲 API
  // 返回指定歌曲ID的歌曲
  getSongOfId: (id) => get(`song/detail?id=${id}`),
  // 返回指定歌曲ID的相似歌曲
  getSimilarSong: (id) => get(`song/similar?id=${id}`),
  // 返回指定歌手ID的歌曲
  getSongOfSingerId: (id) => get(`song/singer/detail?singerId=${id}`),
  // 返回指定歌手名的歌曲
  getSongOfSingerName: (keywords) =>
    get(`song/singerName/detail?name=${keywords}`),
  // 下载音乐
  downloadMusic: (url) => get(url, { responseType: "blob" }),
  // =======================> 社区API
  //删除文章
  deleteArticle: (article_id) => get(`article/delete?article_id=${article_id}`),
  //获得关注者文章
  getSuchArticle: (user_id) => get(`article/getsubarticle?user_id=${user_id}`),
  //搜索文章
  searchArticle: (params) => post(`article/list`, params),
  //获取文章评论
  getComments: (params) => post(`articlecomment/list`, params),
  //增加文章
  addArticle: (params) => post(`article/add`, params),
  //增加文章评论
  addComment: (params) => post(`articlecomment/add`, params),
  //删除歌单
  deleteSongSheet: (id) => get(`songList/delete?id=${id}`),
  //获得所有关注者
  getAllSubscribers: (id) => get(`user/subscribers?id=${id}`),
  //删除歌单指定歌曲
  deleteListSong: (songListId, songId) =>
    get(`listSong/delete?songListId=${songListId}&&songId=${songId}`),
  //点赞
  addLikeCount: (articleId, userId) =>
    get(`article/like?article_id=${articleId}&&user_id=${userId}`),
  //===========================活动api
  //显示所有活动信息
  getAllApplication: () => post(`show/list`),
};

export { HttpManager };
